package pl.wroc.uni.ii.evolution.sampleimplementation.comparision;

import pl.wroc.uni.ii.evolution.engine.EvAlgorithm;
import pl.wroc.uni.ii.evolution.engine.individuals.EvBinaryVectorIndividual;
import pl.wroc.uni.ii.evolution.engine.operators.general.composition.EvReplacementComposition;
import pl.wroc.uni.ii.evolution.engine.operators.general.display.EvRealtimeToPrintStreamStatistics;
import pl.wroc.uni.ii.evolution.engine.operators.general.replacement.EvBestFromUnionReplacement;
import pl.wroc.uni.ii.evolution.engine.operators.general.selections.EvTournamentSelection;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.EvBinaryVectorBOAOperator;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.boa.bayesnetwork.EvBinaryBayesianNetwork;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.boa.metrics.EvBayesianDirchletMetric;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.boa.strategies.EvGreedyStrategy;
import pl.wroc.uni.ii.evolution.engine.prototype.EvObjectiveFunction;
import pl.wroc.uni.ii.evolution.engine.prototype.EvTask;
import pl.wroc.uni.ii.evolution.engine.terminationconditions.EvMaxIteration;
import pl.wroc.uni.ii.evolution.objectivefunctions.Ev3Deceptive;
import pl.wroc.uni.ii.evolution.solutionspaces.EvBinaryVectorSpace;

public class EvBOAExample {

  public static void main(String[] args) {   
    
    EvTask evolutionary_task = new EvTask();
        
    EvAlgorithm<EvBinaryVectorIndividual> genericEA;
   
    EvObjectiveFunction<EvBinaryVectorIndividual> objective_function = 
      new Ev3Deceptive();
    
    genericEA = new EvAlgorithm<EvBinaryVectorIndividual>(3000);
    genericEA.setSolutionSpace(new EvBinaryVectorSpace(objective_function, 60));
   
    genericEA.addOperator(new EvRealtimeToPrintStreamStatistics<EvBinaryVectorIndividual>(System.out));
    
  
    genericEA.addOperator(new EvTournamentSelection<EvBinaryVectorIndividual>(4, 1));
    
    genericEA.addOperator(
        new EvReplacementComposition<EvBinaryVectorIndividual>(
        new EvBinaryVectorBOAOperator<EvBinaryVectorIndividual>(
            new EvBinaryBayesianNetwork(3),
            new EvBayesianDirchletMetric(),
            new EvGreedyStrategy<EvBinaryVectorIndividual>(20),
            1500),
        new EvBestFromUnionReplacement<EvBinaryVectorIndividual>())); 
    
             
    genericEA.setTerminationCondition(new EvMaxIteration<EvBinaryVectorIndividual>(15));
   
    evolutionary_task.setAlgorithm(genericEA);
    long cur_time = System.currentTimeMillis();
    evolutionary_task.run();
    //evolutionary_task.printBestResult();
    long after_time = System.currentTimeMillis();
    System.out.println("RUN TIME: " + (after_time - cur_time) + " sec");
  }

}
